import tensorflow as tf
import numpy as np
from tensorflow.keras.datasets import fashion_mnist # type: ignore

# Load the pre-trained model
loaded_model = tf.keras.models.load_model('mnist_model.h5')

# Load the Fashion MNIST dataset
(x_train, y_train), (x_test, y_test) = fashion_mnist.load_data()

# Preprocess the data
x_test = x_test / 255.0

# Make predictions using the loaded model
predictions = loaded_model.predict(x_test)

# Display the first 5 prediction results
for i in range(5):
    print(f"True label: {y_test[i]}")
    print(f"Predicted label: {np.argmax(predictions[i])}\n")

# Calculate overall accuracy
accuracy = np.mean(np.argmax(predictions, axis=1) == y_test)

# Display the overall accuracy
print(f"Overall Accuracy: {accuracy * 100:.2f}%")